<?php


namespace App\Zesow\Cache\Impl;

use Illuminate\Support\Facades\Cache;
use App\Services\Other\Interfaces\LinkServiceInterface;
use function React\Promise\all;

class LinkCache
{

    public const KEY_NAME = 'links';

    private $linkService;

    public function __construct(LinkServiceInterface $linkService)
    {
        $this->linkService = $linkService;
    }

    public function get()
    {
        if (Cache::has(self::KEY_NAME)) {
            return Cache::get(self::KEY_NAME);
        }
        $links = $this->linkService->all();
        Cache::put(self::KEY_NAME, $links);
        return $links;

    }

    public function destroy()
    {
        Cache::forget(self::KEY_NAME);
    }

}
